package com.example.service.impl;

import com.example.mapper.suspectListMapp;
import com.example.pojo.suspectListPojo;
import com.example.service.suspectListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * ClassName:suspectListImpl
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/10/5 0:21
 * @Version 1.0
 */
@Service
public class suspectListImpl implements suspectListService {
    @Autowired
    private suspectListMapp suspectListMapp;
    //插入一行数据
    public suspectListPojo insertOne(suspectListPojo suspectListPojo){
        //组合时间
        suspectListPojo.setUpdateTime(LocalDateTime.now());
        suspectListPojo.setEstablishTime(LocalDateTime.now());
        //插入一行
        int rowsAffected=suspectListMapp.insertOne(suspectListPojo);
        System.out.println(rowsAffected);
        //根据ID，查询一行，查询的是刚才插入的这一行
        suspectListPojo pojo=suspectListMapp.selectOneById(rowsAffected);
        return pojo;
    }
    //查询所有数据
    public List<suspectListPojo> selectAll(){
        //查询所有数据
        List<suspectListPojo> suspectListPojos=suspectListMapp.selectAll();
        return suspectListPojos;
    }
    //根据id，修改一个字段的值
    public void EditOneFiledById(Map<String, Object> map){
        Integer id=(Integer) map.get("id");
        String filedName=(String) map.get("filedName");
        String filedVal=(String) map.get("filedVal");
        suspectListMapp.editOneFiledById(id,filedName,filedVal);
    }
    //根据id，修改一行的数据，用在了对大表修改上
    public void EditFiledById(suspectListPojo suspectListPojo){
        //组合时间
        suspectListPojo.setUpdateTime(LocalDateTime.now());
        suspectListMapp.EditFiledById(suspectListPojo);
    }
}
